import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class CoreWechatApiService extends BaseService<any> {
  private readonly logger = new Logger(CoreWechatApiService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * userInfo
   * 对应 PHP: CoreWechatApiService_core::userInfo()
   * 逻辑类型: undefined - undefined
   */
  async userInfo(site_id: number, openid: number) {
    // 基于PHP真实逻辑: userInfo
    // PHP原文: $api = CoreWechatService::appApiClient($site_id);         return $api->get('/cgi-bin/user/info', [             'openid' => $openid,         ]);     } ...
const api = CoreWechatService.appApiClient(site_id);
        return api.get('/cgi-bin/user/info', [
            openid: openid,
        )];
    }

    /**
     * 批量获取用户基本信息
     * @param int site_id
     * @param openids
     * @param string lang
     * @return mixed
     * @throws GuzzleBusinessException
     * @throws InvalidConfigBusinessException
     */
    async userInfoBatchget(int site_id, openids, string lang = 'zh_CN')
    {
        return CoreWechatService.appApiClient(site_id).postJson('/cgi-bin/user/info/batchget', [
                user_list: any[)_map(function(openid) use (lang) {
                    return [
                        openid: openid,
                        lang: lang,
                    ];
  }

  /**
   * userInfoBatchget
   * 对应 PHP: CoreWechatApiService_core::userInfoBatchget()
   * 逻辑类型: undefined - undefined
   */
  async userInfoBatchget(site_id: any[], openids: any[], lang: any[]) {
    // 基于PHP真实逻辑: userInfoBatchget
    // PHP原文: return CoreWechatService::appApiClient($site_id)->postJson('/cgi-bin/user/info/batchget', [                 'user_list' => array_map(function($openid)...
return CoreWechatService.appApiClient(site_id).postJson('/cgi-bin/user/info/batchget', [
                user_list: any[)_map(function(openid) use (lang) {
                    return [
                        openid: openid,
                        lang: lang,
                    ];
  }

  /**
   * userGet
   * 对应 PHP: CoreWechatApiService_core::userGet()
   * 逻辑类型: undefined - undefined
   */
  async userGet(site_id: number, next_openid: number) {
    // 基于PHP真实逻辑: userGet
    // PHP原文: $api = CoreWechatService::appApiClient($site_id);         return $api->get('/cgi-bin/user/get', [ 'next_openid' => $next_openid ]);     }      /**    ...
const api = CoreWechatService.appApiClient(site_id);
        return api.get('/cgi-bin/user/get', [ next_openid: next_openid )];
    }

    /**
     * 创建菜单按钮接口
     * @param int site_id
     * @param buttons
     * @param match_rule
     * @return mixed
     * @throws GuzzleBusinessException
     * @throws InvalidConfigBusinessException
     */
    async menuCreate(int site_id, buttons, match_rule = [))
    {
        const api = CoreWechatService.appApiClient(site_id);
        if (!!match_rule)) {
            return api.postJson('cgi-bin/menu/addconditional', [
                button: buttons,
                matchrule: match_rule,
            )];
  }

  /**
   * menuCreate
   * 对应 PHP: CoreWechatApiService_core::menuCreate()
   * 逻辑类型: undefined - undefined
   */
  async menuCreate(site_id: any[], buttons: any[], match_rule: any[]) {
    // 基于PHP真实逻辑: menuCreate
    // PHP原文: $api = CoreWechatService::appApiClient($site_id);         if (!empty($match_rule)) {             return $api->postJson('cgi-bin/menu/addconditional', ...
const api = CoreWechatService.appApiClient(site_id);
        if (!!match_rule)) {
            return api.postJson('cgi-bin/menu/addconditional', [
                button: buttons,
                matchrule: match_rule,
            )];
  }
}
